package demo.practice.binary_search;

public class Ms1005 {

    public static void main(String[] args) {
        System.out.println("at".compareTo("bt"));

        Ms1005 ms1005= new Ms1005();
        int ta = ms1005.findString(new String[]{"at", "", "", "", "ball", "", "", "car", "", "", "dad", "", ""}, "ta");
        System.out.println(ta);
    }

    public int findString(String[] words, String s) {
        int min = 0;
        int max = words.length - 1;


        while (min <= max) {
            int mid = min + (max - min) / 2;
            while (mid <words.length-1 && words[mid].equals(""))
                mid++;

            if (words[mid].equals(s)) {
                return mid;
            } else if (words[mid].compareTo(s) > 0)
                //mid比s大 ，s应该在前面
                max = mid - 1;
            else
                min = mid + 1;
        }
        return -1;
    }
}
